import { PrismaClient } from "@prisma/client";

const prisma = new PrismaClient().$extends({
    model: {
        club: {
            async getJoinable(){
                const clubs = await prisma.club.findMany({
                    include: {
                        members: true,
                        department: true
                    }
                })
                return clubs.filter(c=>c.capacity>c.members.length).map(c=>{
                    c.availableCapacity=c.capacity-c.members.length
                    c.department = c.department.name
                    delete c.members
                    delete c.dept_id
                    return c
                })
            }
        } 
    }
})

export default prisma